function leadTable(){

    $('#lectureTb').bootstrapTable({
        url:'/api/getbypagelecture',
        striped:true,//设置为true会有隔行变色效果
        pagination:true,//设置为true会在底部显示分页条
        singleSelect: false,//设置为false将禁止多选
        pageSize:7,//如果设置了分页，每页数据条数
        pageList:[7],
        pageNumber:1,//如果设置了分页。首页页码
        sidePagination: "server",//设置在哪里进行分页，可选项为“client”
        responseHandler: function (res) {
            return{                            //return bootstrap-table能处理的数据格式
                "total":res.data.total,
                "rows":res.data.rows
            }
        },
        queryParams:function (params){
            let paraObj = {
                size:params.limit,
                page:params.offset/params.limit,
                sort:"sid",
                direct:"desc",
                tname:$("#searchTeacherName").val(),
                cname:$("#searchCourseName").val()
            };

            return paraObj;
        },
        columns:[{
            field:'lid',
            title:'序号'
        },{
            field: 'lno',
            title: '授课编号'
        },{
            field: 'tno',
            title: '学号'
        },{
            field: 'tname',
            title: '姓名'
        },{
            field: 'cno',
            title: '课程编号'
        },{
            field: 'cname',
            title: '课程名称'
        },{
            title: '操作',
            width: '100px',
            formatter:function (data, row, meta){
                let operators = '<a href="#" class="btn btn-mint btn-xs btn-icon" onclick=editLecture(' + row.lid + ') title="title">编辑</a> ' +
                    '<a href="#" class="btn btn-mint btn-xs btn-icon" onclick=deleteLecture(' + row.lid + ') title="title">删除</a>';
                return operators;
            }
        }]
    });
}

function search(){
    $('#lectureTb').bootstrapTable("destroy");
    leadTable();
}

function resetsearch(){
    tname:$("#searchTeacherName").val("");
    cname:$("#searchCourseName").val("");
    search();
}

//
// function leadTable(){
//
//     let inputname = $('#inputname').val();
//     let a = "";
//     if(inputname != ""){
//         a = "/api/student/list?name="+inputname;
//     }else{
//         a = "/api/student/list"
//     }
//     $.ajax({
//         method:'GET',
//         url:a
//     }).done(function (rs) {
//             console.log(JSON.stringify(rs))
//             let html = "";
//             rs.forEach(function (item) {
//                 html += "<tr>"
//                     + "<td>" + item.id + "</td>"
//                     + "<td>" + item.no + "</td>"
//                     + "<td>" + item.name + "</td>"
//                     + "<td>" + item.sex + "</td>"
//                     + "<td>" + item.classname + "</td>"
//                     + "<td>" + item.age + "</td>"
//                     + "<td>" + item.score + "</td>"
//
//                     + "<td> <a href='#' onclick='editStudent(" + item.id + ")'>编辑</a>   <a href='#' onclick='deleteStudent(" +
//                     item.id + ")'>删除</a></td>"
//
//                     + "</tr>";
//             });
//             $("#studentTb").html(html);
//         }
//     )
// }

function saveLecture(){
    let data = $("#lectureform").serialize();

    let id = $("#lid").val();
    let requestObj = null;
    if(id < 1){
        requestObj = {
            method: 'post',
            url: '/api/lectureinsert',
            data:data
        }
    }
    else {
        //更新
        requestObj = {
            method: 'put',
            url: '/api/lectureupdate',
            data:data
        }
    }

    $.ajax(requestObj).done(function (){
        $('#lectureModel').modal('hide');
        $('#lectureTb').bootstrapTable("destroy");
        leadTable();
    });
}

function editLecture(lid){

    // $('#studentModel').modal('show');
    $.ajax({
        method:'GET',
        url:'/api/lectureget/'+lid
    }).done(function (rs){
        $('#lid').val(rs.data.lid);
        $('#lno').val(rs.data.lno);
        $('#tno').val(rs.data.tno);
        $('#tname').val(rs.data.tname);
        $('#cno').val(rs.data.cno);
        $('#cname').val(rs.data.cname);
        $('#lectureModel').modal('show');
    });
}

function preAdd(){
    $("#lid").val(0);//提示新增
    $('#lectureModel').modal('show');

}

function deleteLecture(id) {
    if (confirm("您是否真的要删除吗？别后悔哦！")) {
        $.ajax({
            method: 'delete',
            url: '/api/lecturedelete/' + id
        }).done(function () {
            $('#lectureTb').bootstrapTable("destroy");
            leadTable();
        });
    }// end if
}

function clearForm(){
    $("#lno").val("");
    $("#tno").val("");
    $("#tname").val("");
    $("#cno").val("");
    $("#cname").val("");

}

$(function () {

    leadTable();
})

$('#lectureModel').on('hidden.bs.modal',clearForm)//清空代码